package yxy.game.pm2.command.plainsarena;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsArenaMessage;
import yxy.game.pm2.module.plainsarena.PlainsArenaHandle;

/** 中原擂台 中原擂台挑战 */
@MessageType(proto = Command.PlainsArenaChanllenge, classtype = PlainsArenaMessage.PlainsArenaChanllengeRequest.class)
public class CMD_PlainsArenaChanllenge extends Command<PlainsArenaMessage.PlainsArenaChanllengeRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsArenaMessage.PlainsArenaChanllengeRequest request) {
		try {
			String playerCode = messageSource.getTag();
			int rank = request.getRank();
			boolean skip = request.getSkip();

			PlainsArenaMessage.PlainsArenaChanllengeResponse.Builder response = PlainsArenaMessage.PlainsArenaChanllengeResponse.newBuilder();

			Result result = new PlainsArenaHandle().battleResponseExecute(playerCode, rank, skip, response);

			send(messageSource, response, result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void send(MessageSource messageSource, PlainsArenaMessage.PlainsArenaChanllengeResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}